package com.buaa.aimall.computeModule.Controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.buaa.aimall.Utils.BaseResponse;
import com.buaa.aimall.Utils.Enum.StatusCode;
import com.buaa.aimall.Utils.PageReturnResult;
import com.buaa.aimall.computeModule.Entity.ComputeResourceEntity;
import com.buaa.aimall.computeModule.Service.ComputeResourceService;
import com.buaa.aimall.userModule.DTO.PageDTO;
import com.buaa.aimall.userModule.Entity.UserEntity;
import com.buaa.aimall.userModule.Service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/compute/resource")
@CrossOrigin
public class ComputeResourceController {
    @Autowired
    private UserService userService;

    @Autowired
    private ComputeResourceService computeResourceService;

    @PostMapping("filter-compute-resource")
    public BaseResponse<PageReturnResult<ComputeResourceEntity>> filterComputeResource(@RequestBody PageDTO pageDTO) {
        UserEntity userEntity = userService.getCurrentUser();
        var result = computeResourceService.getByOwner(new Page<>(pageDTO.getCurrentPage(), pageDTO.getPageSize()), userEntity.getId());
        return new BaseResponse<>(StatusCode.SUCCESS, "获取算力资源成功", result);
    }
}
